/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dp1.pucp.Logistica.Vista;

import com.dp1.pucp.Modelo.Clases.*;
import com.dp1.pucp.Logistica.Controlador.*;
import com.dp1.pucp.Util.Validaciones;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author daniek
 */
public class AjustesAlmacenGUI extends javax.swing.JPanel {

    /**
     * Creates new form BuscarUsuarioGUI
     */
    private JFrame padre;
    private TipoProductoControlador c;
    private BuscarMateriaPrimaGUI materiaPrima;
    public ArrayList<Almacen> listaAlmacen = new ArrayList<>();

    public AjustesAlmacenGUI() {
        initComponents();
        txtCodProd.setVisible(false);
        txtCodPres.setVisible(false);
    }
    
    public JFrame getPadre(){ return padre; }
    
    public String getIdTipoProducto(){ return txtCodProd.getText().trim(); }
    
    public String getIdPresentacion(){ return txtCodPres.getText().trim(); }
    
    public String getCantidad(){ return txtCantidad.getText().trim(); }
    
    //public int getTipo(){ return cmbTipo.getSelectedIndex(); }      
    
    public int getAlmacen(){ return cmbAlmacen.getSelectedIndex(); } 
    
    
    public int getTipo(){ return cmbTipo.getSelectedIndex(); } 
    
    public int getMotivo(){ return cmbMotivo.getSelectedIndex(); } 
    //public int getFilaSel(){ return tblResultados.getSelectedRow(); }     

    public void mostrarAviso(String msn){
        Validaciones.mostrarMensajeAvisoVal(msn);   
    }
//    public void mostrarError(String msn){
//        Validaciones.mostrarMensajeErrorVal(msn);           
//    }
//    public int solicitarConfirmacion(String msn){
//        return Validaciones.solicitarConfirmacionVal(msn);
//    }
      
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    //public void addNuevoListener(ActionListener ml){ this.btnCrear.addActionListener(ml); }
    
    //public void addBuscarListener(ActionListener ml){ this.btnBuscar.addActionListener(ml); }    

    public void addLimpiarListener(ActionListener ml){
        this.btnLimpiar.addActionListener(ml);
    }
        
    public void addGuardarListener(ActionListener ml){
        this.btnGuardar.addActionListener(ml);
    }
    
    
    
    public void addBuscarProductoListener(ActionListener ml){
        this.btnBuscar.addActionListener(ml);
    }
    
    public void addBuscarPresentacionListener(ActionListener ml){
        this.btnBuscarPres.addActionListener(ml);
    }
    
    public void addVerAlmacenListener(ActionListener ml){
        this.btnAlmacen.addActionListener(ml);
    }
    
    public void llenaComboTipo(ArrayList<String> lista){
        if(lista!=null){
            for (String opc : lista){
                cmbTipo.addItem(opc);
            }
        }
    } 
    
    
    public void setFormUsuarioT(Tipoproducto u){
        
        if(u!=null){

        txtCodProd.setText(String.valueOf(u.getIdtipoproducto()));
        txtNombre.setText(String.valueOf(u.getNombre()));
        
        if(u.getTipo().equals("MP")){
            cmbTipo.setSelectedIndex(0);
        }
        if(u.getTipo().equals("PI")){
            cmbTipo.setSelectedIndex(1);
        }
        if(u.getTipo().equals("PF")){
            cmbTipo.setSelectedIndex(2);
        }
        
        if(u.getTipo().equals("MP")){
            cmbAlmacen.setSelectedIndex(0);
        }
        if(u.getTipo().equals("PI")){
            cmbAlmacen.setSelectedIndex(1);
        }
        if(u.getTipo().equals("PF")){
            cmbAlmacen.setSelectedIndex(2);
        }
        
        if(u.getTipo().equals("MP"))
        btnBuscarPres.setEnabled(false);
            //lblPresentacion.setVisible(false);
            //txtPresentacion.setVisible(false);
            //btnBuscarPres.setVisible(false);
        }
    }
        
    public void setFormUsuarioP(Presentacion p){
        
        if(p!=null){

        txtCodPres.setText(String.valueOf(p.getIdpresentacion()));
        txtPresentacion.setText(String.valueOf(p.getNombre()));
        }
    }
    
    
    public void llenaComboAlmacen(ArrayList<Almacen> lista){
        if(lista!=null){
            for (Almacen opc : lista){
                cmbAlmacen.addItem(opc.getNombre());
            }
             listaAlmacen = lista;
        }
    }
    
    public void llenaComboMotivo(ArrayList<String> lista){
        if(lista!=null){
            for (String opc : lista){
                cmbMotivo.addItem(opc);
            }
             //listaAlmacen = lista;
        }
    }
    
    public void LimpiarDatos(){
        txtNombre.setText("");
        txtCodProd.setText("");
        txtCodPres.setText("");
        txtCantidad.setText("");
        txtPresentacion.setText("");
        btnBuscarPres.setEnabled(true);
        cmbAlmacen.setSelectedIndex(0);
        cmbMotivo.setSelectedIndex(0);
        //cmbTipo.setSelectedIndex(0);     
        //((DefaultTableModel) this.tblResultados.getModel()).setRowCount(0);
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        btnGuardar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtCantidad = new javax.swing.JTextField();
        cmbMotivo = new javax.swing.JComboBox();
        cmbAlmacen = new javax.swing.JComboBox();
        btnBuscar = new javax.swing.JButton();
        txtCodProd = new javax.swing.JTextField();
        lblPresentacion = new javax.swing.JLabel();
        txtPresentacion = new javax.swing.JTextField();
        btnBuscarPres = new javax.swing.JButton();
        txtCodPres = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cmbTipo = new javax.swing.JComboBox();
        btnAlmacen = new javax.swing.JButton();

        setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setMaximumSize(new java.awt.Dimension(683, 663));
        setMinimumSize(new java.awt.Dimension(400, 400));
        setPreferredSize(new java.awt.Dimension(683, 663));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos"));

        jLabel3.setText("Producto");

        txtNombre.setEnabled(false);
        txtNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombreActionPerformed(evt);
            }
        });

        btnGuardar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/save.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.setBorderPainted(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnLimpiar.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/clear.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.setBorderPainted(false);
        btnLimpiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnLimpiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jLabel8.setText("Motivo");

        jLabel4.setText("Almacen");

        jLabel1.setText("Cantidad");

        txtCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCantidadKeyTyped(evt);
            }
        });

        cmbAlmacen.setEnabled(false);

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/buscarChico.png"))); // NOI18N
        btnBuscar.setBorderPainted(false);

        lblPresentacion.setText("Presentacion");

        txtPresentacion.setEnabled(false);

        btnBuscarPres.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/buscarChico.png"))); // NOI18N
        btnBuscarPres.setBorderPainted(false);

        jLabel5.setText("Tipo");

        cmbTipo.setEnabled(false);

        btnAlmacen.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        btnAlmacen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/see.png"))); // NOI18N
        btnAlmacen.setText("Ver Almacen");
        btnAlmacen.setBorderPainted(false);
        btnAlmacen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAlmacen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtCodProd, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(lblPresentacion)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8)
                            .addComponent(jLabel1))
                        .addGap(42, 42, 42))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtCodPres, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(175, 175, 175)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbMotivo, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtPresentacion, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscarPres, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(56, 57, Short.MAX_VALUE)
                .addComponent(btnAlmacen)
                .addGap(76, 76, 76))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(51, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnBuscar)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtCodProd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cmbAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtPresentacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblPresentacion))
                    .addComponent(btnBuscarPres))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbMotivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(txtCodPres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(btnAlmacen)
                                .addGap(14, 14, 14))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnGuardar)
                            .addComponent(btnLimpiar))
                        .addGap(25, 25, 25))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 197, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombreActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombreActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void txtCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadKeyTyped
        // TODO add your handling code here:
        String car = txtCantidad.getText();
        if(car.length()>=5) evt.consume();        
        Validaciones.soloDigito(evt);
    }//GEN-LAST:event_txtCantidadKeyTyped
  
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlmacen;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnBuscarPres;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JComboBox cmbAlmacen;
    private javax.swing.JComboBox cmbMotivo;
    private javax.swing.JComboBox cmbTipo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblPresentacion;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtCodPres;
    private javax.swing.JTextField txtCodProd;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtPresentacion;
    // End of variables declaration//GEN-END:variables
}
